package com.ittsang.controller;

import com.ittsang.dto.ArticleDTO;
import com.ittsang.dto.PageDTO;
import com.ittsang.dto.R;
import com.ittsang.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     *  获取所有文章
     * @return
     */
    @PostMapping("/getArticle")
    public R getArticle(@RequestBody PageDTO req) {
        // 图片地址，id，创建时间，评论数，阅读数，是否置顶，标题，详情
        return articleService.getArticle(req);
    }

    /**
     *  根据文章类型id获取文章列表
     * @param req
     * @return
     */
    @PostMapping("/getArticleByType")
    public R getArticleByType(@RequestBody PageDTO req) {
        return articleService.getArticleByType(req);
    }

    /**
     *  根据文章id获取文章信息
     * @param articleId
     * @return
     */
    @GetMapping("/getArticleInfoById")
    public R getArticleInfoById(@RequestParam("articleId") Integer articleId) {
        return articleService.getArticleInfoById(articleId);
    }

    /**
     *  根据文章id删除文章
     * @param articleId
     * @return
     */
    @GetMapping("/deletedArticleById")
    public R deletedArticleById(@RequestParam("articleId") Integer articleId) {
        return articleService.deletedArticleById(articleId);
    }

    /**
     *  根据文章id修改文章内容
     * @param articleDTO
     * @return
     */
    @PostMapping("/alterArticleById")
    public R alterArticleById(ArticleDTO articleDTO) {
        return articleService.alterArticleById(articleDTO);
    }

    /**
     *  新增文章
     * @param articleDTO
     * @return
     */
    @PostMapping("/insertArticle")
    public R insertArticle(@RequestBody ArticleDTO articleDTO) {
        return articleService.insertArticle(articleDTO);
    }

    /**
     *  根据文章id封禁违规文章
     * @param articleId
     * @return
     */
    public R bannedArticleById(@RequestParam("articleId") Integer articleId) {
        return articleService.bannedArticleById(articleId);
    }

    /**
     *  根据文章标题查询文章
     * @param req
     * @return
     */
    @PostMapping("/search")
    public R queryArticleTitle(@RequestBody PageDTO req) {
        return articleService.queryArticleTitle(req);
    }

    /**
     *  获取未审核文章内容，社团为条件
     * @return
     */
    @PostMapping("/getNotReviewedArticle")
    public R getNotReviewedArticle(@RequestBody PageDTO pageDTO) {
        return articleService.getNotReviewedArticle(pageDTO);
    }

    /**
     *  通过审核文章
     * @return
     */
    @GetMapping("/reviewedArticle")
    public R reviewedArticle(@RequestParam("articleId") Integer articleId) {
        return articleService.reviewedArticle(articleId);
    }

    /**
     *  不通过审核文章
     * @param articleId
     * @return
     */
    @GetMapping("/unReviewedArticle")
    public R unReviewedArticle(@RequestParam("articleId") Integer articleId) {
        return articleService.unReviewedArticle(articleId);
    }

    /**
     *  获取未经审核的文章
     * @param pageDTO
     * @return
     */
    public R getNoReviewedArticle(PageDTO pageDTO) {
        return null;
    }

    /**
     *  点赞文章
     * @param articleId
     * @return
     */
    @GetMapping("/like")
    public R thumbsUp(@RequestParam("articleId") Integer articleId) {
        return articleService.thumbsUp(articleId);
    }

    /**
     *  取消点赞
     * @param articleId
     * @return
     */
    @GetMapping("/unLike")
    public R unLike(@RequestParam("articleId") Integer articleId) {
        return articleService.unLike(articleId);
    }

    /**
     *  收藏文章
     * @param articleId
     * @return
     */
    @GetMapping("/cart")
    public R collection(@RequestParam("articleId") Integer articleId) {
        return articleService.collection(articleId);
    }

    /**
     *  取消收藏
     * @param articleId
     * @return
     */
    @GetMapping("/unCart")
    public R unFavorite(@RequestParam("articleId") Integer articleId) {
        return articleService.unFavorite(articleId);
    }

    /**
     *  获取当前用户文章
     * @return
     */
    @PostMapping("/getUserArticle")
    public R getUserArticle(@RequestBody PageDTO pageDTO) {
        return articleService.getUserArticle(pageDTO);
    }

    /**
     *  获取用户收藏文章
     * @param pageDTO
     * @return
     */
    @PostMapping("/getUserCartArticle")
    public R getUserCartArticle(@RequestBody PageDTO pageDTO) {
        return articleService.getUserCartArticle(pageDTO);
    }

    /**
     *  获取用户点赞文章
     * @param pageDTO
     * @return
     */
    @PostMapping("/getUserLikeArticle")
    public R getUserLiketArticle(@RequestBody PageDTO pageDTO) {
        return articleService.getUserLiketArticle(pageDTO);
    }


    @PostMapping("/getUserRecordArticle")
    public R getUserRecordArticle(@RequestBody PageDTO pageDTO) {
        return articleService.getUserRecordArticle(pageDTO);
    }

    @GetMapping("/deletedRecord")
    public R deletedRecord() {
        return articleService.deletedRecord();
    }
}
